package psgExamples;

import com.transmote.psg.PSpriteContainer;

import processing.core.PApplet;


public class PSGExamples extends PApplet {
	private static final long serialVersionUID = 5234264381753823054L;
	
	private PSpriteContainer spriteContainer;
	private TestSprite sprite1 = null;
	private TestSprite sprite2 = null;
	private TestSprite sprite3 = null;
	
	public void setup() {
		size(800, 600);
		frameRate(60);
		
		setupSprites();
//		testAddAt();
	}

	public void draw() {
		background(0);
		spriteContainer.update();
	}
	
	public void mousePressed () {
//		sprite1.testEventDispatching();
	}
	
	public static void main(String _args[]) {
		PApplet.main(new String[] { psgExamples.PSGExamples.class.getName() });
	}
	
	private void setupSprites () {
		sprite1 = new TestSprite(1);
		sprite1.setBounds(-100, -100, 200, 200);
		sprite1.x = 0.5f * width;
		sprite1.y = 0.5f * height;
		sprite1.rotationZ = -0.5f;
		
		sprite2 = new TestSprite(2);
		sprite2.setBounds(-50, -50, 100, 100);
		sprite2.x = 75;//50;
		sprite2.y = 75;//50;
//		sprite2.rotationZ = 0.5f;
//		sprite2.testEventHandling(sprite1);
//		sprite2.inputChildren = false;
//		sprite2.testEventPropagation();
		sprite2.handleCaptureEvents = true;
		
		sprite3 = new TestSprite(3);
		sprite3.setBounds(-50, -50, 100, 100);
		sprite3.x = 50;
		sprite3.y = 50;
		
		spriteContainer = new PSpriteContainer(this);
		spriteContainer.addChild(sprite1);
		sprite1.addChild(sprite2);
		sprite2.addChild(sprite3);
	}
	/*
	private void testAddAt () {
		sprite3 = new TestSprite();
		sprite3.setBounds(-150, -150, 300, 300);
		sprite3.speed = -0.005f;
		sprite3.color = 0xFFFFCC33;
		sprite3.x = sprite1.x;
		sprite3.y = sprite1.y;
		spriteContainer.addChild(0, sprite3);
	}
	
	public void keyPressed () {
		if (sprite2 == null || sprite3 == null) { return; }
		
		if (key == 's') {
			// reparenting
			if (sprite2.parent() == sprite1) {
				sprite3.addChild(sprite2);
			} else {
				sprite1.addChild(sprite2);
			}
		}
	}
	*/
}
